import router from '@/router/index.js'
import store from '@/store/index.js'
// 每一次跳转页面都从这里过
router.beforeEach((to, from, next) => {
  // 白名单,不需要token就可以访问
  const whiteList = ['/login', '/404']
  // 是否有token
  // if (store.state.user.token) {
  if (store.getters.token) {
    // 是否是登录页面,跳转到主页
    if (to.path === '/login') return next('/')
    // 放行
    next()
  } else if (whiteList.includes(to.path)) {
    next()
  } else {
    next('/login')
  }
})
